package com.ushine.web.template.authority.view;

import com.ushine.web.base.model.system.OrgDO;
import com.ushine.web.base.model.system.PostDO;
import com.ushine.web.template.authority.model.StaffDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Optional;

/**
 * @Author: yls
 * @Date: 2022/03/01 09:33
 * @Description: 模拟多表联查权限数据
 * @Version 1.0
 */
@Data
public class StaffVO {
    /**
     * 用户名
     */
    @ApiModelProperty("用户名")
    private String username;

    /**
     * 查询对应的组织表
     */
    @ApiModelProperty("组织名称")
    private String orgName;

    /**
     * 查询对应的岗位表
     */
    @ApiModelProperty("岗位名称")
    private String postName;


    public static StaffVO convertVO(StaffDO staff, PostDO post, OrgDO org) {
        staff = Optional.ofNullable(staff).orElse(new StaffDO());
        post = Optional.ofNullable(post).orElse(new PostDO());
        org = Optional.ofNullable(org).orElse(new OrgDO());
        StaffVO staffVO = new StaffVO();
        staffVO.setOrgName(org.getOrgName());
        staffVO.setPostName(post.getPostName());
        staffVO.setUsername(staff.getUsername());
        return staffVO;
    }
}
